/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package model;

import database.DBConnection;
import java.io.IOException;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
import util.PropertiesManager;

/**
 *
 * @author rosana
 */
public class ConvenioDAO implements OperacoesDAO {
  
      private Connection conexao;

    public ConvenioDAO() throws ClassNotFoundException, SQLException {
        conexao = DBConnection.getConnection();

    }
    @Override
    public void inserir(Object obj) throws SQLException {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public boolean excluir(Object obj) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void editar(Object obj) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

      @Override
    public ArrayList pesquisar() throws SQLException {
        ArrayList retorno = new ArrayList();
        String SQL = buscaSQL("selectAll.Convenio");
        Statement st = conexao.createStatement();
        ResultSet res = st.executeQuery(SQL);
        while (res.next()) {
            int idConvenio = res.getInt(1);
            String nome = res.getString(2);
            Convenio con = new Convenio(idConvenio, nome);
            retorno.add(con);
        }
        return retorno;
    }
      
      public void FunctionInfoConvenio(Object obj) throws SQLException {
            Convenio com = (Convenio) obj;
            CallableStatement cs = conexao.prepareCall("{call proc_convenio_pago (?)}"); 
            cs.setString(1,com.getNome());            
            cs.execute();
    }
    
    
     private String buscaSQL(String chave) {
        String sql = null;
        try {
            PropertiesManager pm = new PropertiesManager("sql.properties");
            HashMap dados = pm.readPropertiesFile();
            sql = (String) dados.get(chave);
        } catch (IOException ex) {
            Logger.getLogger(ConvenioDAO.class.getName()).log(Level.SEVERE, null, ex);
        }
        return sql;
    }
    
}
